package playn101.core;

import static playn.core.PlayN.*;

import playn.core.Game;
import playn.core.Image;
import playn.core.ImageLayer;
import playn.core.Canvas;
import playn.core.CanvasImage;

public class C implements Game {
  CanvasImage bgImage;
  ImageLayer bgLayer;
  Image cloudImage;
  ImageLayer cloudLayer;
  float x;
  float y;

  @Override
  public void init() {
    bgImage = graphics().createImage(800, 600);
    Canvas canvas = bgImage.canvas();
    canvas.setFillColor(0xff87ceeb);
    canvas.fillRect(0, 0, 800, 600);
    bgLayer = graphics().createImageLayer(bgImage);
    graphics().rootLayer().add(bgLayer);
    cloudImage = assetManager().getImage("images/cloud.png");
    cloudLayer = graphics().createImageLayer(cloudImage);
    graphics().rootLayer().add(cloudLayer);
    x = 24.0f;
    y = 3.0f;
  }

  @Override
  public void paint(float alpha) {
    // the background automatically paints itself, so no need to do anything here!
  }

  @Override
  public void update(float delta) {
    x += 0.1f * delta;
    if (x > bgImage.width() + cloudImage.width()) {
      x = -cloudImage.width();
    }
    cloudLayer.setTranslation(x, y);
  }

  @Override
  public int updateRate() {
    return 25;
  }
}
